package com.yunsom.testdemo.design.flyweight;

/**
 * @author Xbao
 * @description 享元模式
 * @date 2022/6/21 15:49
 */
public class FlyWeightTest {

  private static final String[] colors = new String[]{"red", "green", "blue", "yellow"};

  public static void main(String[] args) {

    for (int i = 0; i < 20; i++) {
      Circle circle = (Circle) ShapeFactory.getCircle(getRandomColor());
      circle.setRadius(100);
      circle.setX(getRandomX());
      circle.setY(getRandomY());
      circle.draw();
    }
    
  }

  private static String getRandomColor(){
    return colors[(int) (Math.random() * colors.length)];
  }

  private static int getRandomX(){
    return (int) (Math.random() * 100);
  }

  private static int getRandomY(){
    return (int) (Math.random() * 100);
  }

}
